import json

from django.http import JsonResponse

# Create your views here.
from rest_framework.generics import GenericAPIView
from rest_framework.views import APIView
from rest_framework.response import Response
from rest_framework.exceptions import NotFound
from rest_framework.mixins import ListModelMixin, CreateModelMixin, RetrieveModelMixin, UpdateModelMixin, \
    DestroyModelMixin

from book.models import BookInfo
from .serializers_2 import BookSerializer


class BooksView(CreateModelMixin, ListModelMixin, GenericAPIView):
    queryset = BookInfo.objects.all()
    serializer_class = BookSerializer

    def post(self, request):
        return self.create(request)

    def get(self, request):
        return self.list(request)


class BookView(DestroyModelMixin, RetrieveModelMixin, UpdateModelMixin, GenericAPIView):
    queryset = BookInfo.objects.all()
    serializer_class = BookSerializer

    def get(self, request, pk):
        return self.retrieve(request)

    def delete(self, request, pk):
        return self.destroy(request)

    def put(self, request, pk):
        return self.update(request)


